package com.hansming.bss.modules.sfc.service;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hansming.bss.common.service.CrudService;
import com.hansming.bss.modules.sfc.dao.CustomerDao;
import com.hansming.bss.modules.sfc.entity.Bindpcinfo;
import com.hansming.bss.modules.sfc.entity.Customer;

/**
 * 顾客用户Service
 * @author Hansming
 * @version 2017-09-19
 */
@Service
@Transactional(readOnly = true)
public class CustomerService extends CrudService<CustomerDao,Customer>{
	
	@Autowired
	private CustomerDao customerDao;
	
	@Transactional(readOnly = false)
	public int savecustomer(Customer customer){
		return customerDao.savecustomer(customer);
	}
	
	
	public Customer findCustomerByEmail(String email,String password){
		return customerDao.findCustomerByEmail(email,password);
	}
	
	public Customer findCustomerByPhone(String phone,String password){
		return customerDao.findCustomerByPhone(phone, password);
	}
	
	public Customer checkEmail(String email){
		return customerDao.checkEmail(email);
	}
	

	
	public void activate(String id){
		customerDao.activate(id);
	}
	
	//小程序授权创建新用户
	@Transactional(readOnly = false)
	public void	savecustomerbyid(String id,String name,int score,String del_flag){
		customerDao.savecustomerbyid(id, name,score,del_flag);
	}
	
	@Transactional(readOnly = false)
	public void updatescore(Customer customer){
		customerDao.updatescore(customer);
	}
	
	
	//检测手机号码是否重复
	public int checkphone(String phone){
		return customerDao.checkphone(phone);
	}
		
	//检测邮箱是否重复
	public int checkemail(String email){
		return customerDao.checkemail(email);
	}
	
	//PC登录
	public Customer login(String phone,String email,String password){
		return customerDao.login(phone, email, password);
	}
	
	
	//根据PcUser的token查找到对应用户的信息
	public Customer selectbypcusertoken(String token){
		return customerDao.selectbypcusertoken(token);
	}
	
	@Transactional(readOnly = false)
	public void update(Customer customer){
		customerDao.update(customer);
	} 
	
	
	public Bindpcinfo selectBindinfoByPcUserId(String pcuserid) {
		return customerDao.selectBindinfoByPcUserId(pcuserid);
	}
}
